package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.*;
import com.heima.wemedia.service.WmNewsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 陈辉
 * @data 2024 10:28
 */
@Slf4j
@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {

    @Autowired
    private WmNewsService wmNewsService;

    /**
     * 内容列表
     *
     * @param reqDto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult list(@RequestBody WmNewsPageReqDto reqDto){
        log.info("查询文章内容列表:{}" , reqDto);
        return wmNewsService.pageQuery(reqDto);
    }

    /**
     * 发布文章
     *
     * @param wmNewsDto
     * @return
     */
    @PostMapping("/submit")
    public ResponseResult submit(@RequestBody WmNewsDto wmNewsDto){
        log.info("发布文章：{}",wmNewsDto);
        return wmNewsService.submit(wmNewsDto);
    }


    /**
     * 根据id查询文章内容
     * @param id
     * @return
     */
    @GetMapping("/one/{id}")
    public ResponseResult oneNews(@PathVariable("id")Integer id){
        //1、日志
        log.info("根据id查询文章内容，id:{}",id);

        //2、调用service进行查询并返回
        return wmNewsService.queryNewsById(id);
    }


    /**
     * 根据id删除文章内容
     * @param id
     * @return
     */
    @GetMapping("/del_news/{id}")
    public ResponseResult deleteNews(@PathVariable("id")Integer id){
        //1、日志
        log.info("根据id删除文章内容，id:{}",id);

        //2、调用service进行删除并返回
        return wmNewsService.deleteNewsById(id);
    }


    /**
     * 自媒体文章上下架
     *
     * @param wmNewsDto
     * @return
     */
    @PostMapping("down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDto wmNewsDto){
        log.info("本次自媒体文章上下架操作：{}", wmNewsDto.getEnable() == 1 ? "上架":"下架");
        return wmNewsService.downOrUp(wmNewsDto);
    }


    /**
     * 自媒体文章分页列表查询
     *
     * @param newsAuthDto
     * @return
     */
    @PostMapping("list_vo")
    public ResponseResult listVo(@RequestBody NewsAuthDto newsAuthDto){
        log.info("自媒体文章列表查询：{}", newsAuthDto);
        return wmNewsService.listVo(newsAuthDto);
    }

    /**
     * 自媒体文章详情查询
     *
     * @param id
     * @return
     */
    @GetMapping("/one_vo/{id}")
    public ResponseResult newsDetail(@PathVariable Integer id){
        log.info("自媒体文章详情查询：{}", id);
        return wmNewsService.queryNewsById(id);
    }

    /**
     * 文章人工审核通过
     *
     * @return
     */
    @PostMapping("/auth_pass")
    public ResponseResult authPass(@RequestBody NewsAuthDto newsAuthDto) {
        log.info("文章人工审核通过：{}",newsAuthDto);
        return wmNewsService.authPass(newsAuthDto);
    }

    /**
     * 文章人工审核失败
     *
     * @return
     */
    @PostMapping("/auth_fail")
    public ResponseResult authFail(@RequestBody NewsAuthDto newsAuthDto) {
        log.info("文章人工审核失败：{}",newsAuthDto);
        return wmNewsService.authFail(newsAuthDto);
    }



}
